cmake_minimum_required(VERSION 3.10)
project(SalaryManagementSystem)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找必要的包
find_package(PkgConfig REQUIRED)

# 查找MySQL (使用pkg-config)
pkg_check_modules(MYSQL REQUIRED mysqlclient)

# 查找OpenSSL
find_package(OpenSSL REQUIRED)

# 查找JsonCPP
find_package(PkgConfig REQUIRED)
pkg_check_modules(JSONCPP jsoncpp)

# 包含目录
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/cpp-httplib)
include_directories(${MYSQL_INCLUDE_DIRS})
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${JSONCPP_INCLUDE_DIRS})

# 源文件
set(SOURCES
    src/main.cpp
    src/db_manager.cpp
    src/auth_manager.cpp
    src/employee_handler.cpp
    src/department_handler.cpp
    src/salary_handler.cpp
    src/attendance_handler.cpp
    src/admin_handler.cpp
)

# 头文件
set(HEADERS
    include/db_manager.h
    include/auth_manager.h
    include/employee_handler.h
    include/department_handler.h
    include/salary_handler.h
    include/attendance_handler.h
    include/admin_handler.h
)

# 创建可执行文件
add_executable(salary_system ${SOURCES} ${HEADERS})

# 链接库
target_link_libraries(salary_system
    ${MYSQL_LIBRARIES}
    ${OPENSSL_LIBRARIES}
    ${JSONCPP_LIBRARIES}
    pthread
    ssl
    crypto
    z
)

# 编译选项
target_compile_options(salary_system PRIVATE
    -Wall
    -Wextra
    -O2
)

# httplib需要的编译定义
target_compile_definitions(salary_system PRIVATE
    CPPHTTPLIB_OPENSSL_SUPPORT
    CPPHTTPLIB_ZLIB_SUPPORT
)

# 打印信息
message(STATUS "MySQL Include Dir: ${MYSQL_INCLUDE_DIRS}")
message(STATUS "MySQL Libraries: ${MYSQL_LIBRARIES}")
message(STATUS "OpenSSL Include Dir: ${OPENSSL_INCLUDE_DIR}")
message(STATUS "OpenSSL Libraries: ${OPENSSL_LIBRARIES}")
message(STATUS "JsonCPP Include Dir: ${JSONCPP_INCLUDE_DIRS}")
message(STATUS "JsonCPP Libraries: ${JSONCPP_LIBRARIES}")